package com.siysoft.util;

import java.net.URLEncoder;

import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;

public class SendMessageUtil {
	
	private static Logger logger = Logger.getLogger(SendMessageUtil.class);
	
	public static boolean send(String phonenum,String content){
		String url ="http://sdk2.sudas.cn:8060/z_mdsmssend.aspx?";
		StringBuffer requestContent = new StringBuffer();
    	try {
    		requestContent
    		.append("&sn=SDK-KEY-010-00109")
    		.append("&pwd=").append(Md5Encrypt.md5("SDK-KEY-010-001091a53e)-e").toUpperCase())
    		.append("&mobile=").append(phonenum).append("&content=")
    		.append(URLEncoder.encode(content+" 【信息中心】","GB2312"))
    		.append("&ext=")
    		.append("&rrid=")
    		.append("&stime=");
    		String res = HttpRequest.getInstance().requestUrl(url+requestContent.toString(),"", true, "POST");
    		logger.info("为"+phonenum+"发送短信， 内容"+content+"短信中心返回:"+res);
    		if((!StringUtils.isEmpty(res))&&res.length()>3){
    			return true;
    		}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return false;
	}
	
	public static void main(String[] args) {
		
		String url ="http://sdk2.sudas.cn:8060/z_mdsmssend.aspx?";
		StringBuffer requestContent = new StringBuffer();
    	try {
    		requestContent
    		.append("&sn=SDK-KEY-010-00109")
    		.append("&pwd=").append(Md5Encrypt.md5("SDK-KEY-010-001091a53e)-e").toUpperCase())
    		.append("&mobile=13294330865").append("&content=")
    		.append(URLEncoder.encode("验证码为：1\n11【房产信息中心】","GB2312"))
    		.append("&ext=")
    		.append("&rrid=")
    		.append("&stime=");
    		String res = HttpRequest.getInstance().requestUrl(url+requestContent.toString(),"", true, "POST");
    		System.out.println(res);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
   